import DataBus from '../databus'
import { SCREEN_WIDTH, SCREEN_HEIGHT } from '../render'

export default class GameControlPanel {
  constructor() {
    this.isVisible = true
    this.databus = new DataBus()
    
    // 控制面板位置和尺寸
    this.panelHeight = 80
    this.panelY = SCREEN_HEIGHT - this.panelHeight - 20
    
    // 按钮配置
    this.buttonWidth = 80
    this.buttonHeight = 50
    this.buttonSpacing = 20
    this.totalButtonWidth = this.buttonWidth * 3 + this.buttonSpacing * 2
    this.startX = (SCREEN_WIDTH - this.totalButtonWidth) / 2
    
    // 按钮定义
    this.undoButton = {
      x: this.startX,
      y: this.panelY - 100,
      width: this.buttonWidth,
      height: this.buttonHeight,
      text: '悔棋',
      color: '#E91E63',
      hoverColor: '#C2185B'
    }

    this.surrenderButton = {
      x: this.startX + this.buttonWidth + this.buttonSpacing,
      y: this.panelY - 100,
      width: this.buttonWidth,
      height: this.buttonHeight,
      text: '认输',
      color: '#FF5722',
      hoverColor: '#E64A19'
    }
    
    this.menuButton = {
      x: this.startX + (this.buttonWidth + this.buttonSpacing) * 2,
      y: this.panelY - 100,
      width: this.buttonWidth,
      height: this.buttonHeight,
      text: '菜单',
      color: '#9C27B0',
      hoverColor: '#7B1FA2'
    }
    
    // 菜单展开状态
    this.isMenuExpanded = false
    this.menuAnimation = 0 // 0-1 动画进度
    
    // 返回按钮
    this.backButton = {
      x: this.startX + (this.buttonWidth + this.buttonSpacing) * 2,
      y: this.panelY - 40,
      width: this.buttonWidth,
      height: this.buttonHeight,
      text: '返回',
      color: '#F44336',
      hoverColor: '#D32F2F'
    }
    
    // 悔棋确认对话框
    this.undoConfirmDialog = {
      isVisible: false,
      x: SCREEN_WIDTH / 2 - 120,
      y: SCREEN_HEIGHT / 2 - 80,
      width: 240,
      height: 160
    }
    
    // 返回确认对话框
    this.backConfirmDialog = {
      isVisible: false,
      x: SCREEN_WIDTH / 2 - 120,
      y: SCREEN_HEIGHT / 2 - 80,
      width: 240,
      height: 160
    }
    
    // 结束游戏确认对话框
    this.surrenderConfirmDialog = {
      isVisible: false,
      x: SCREEN_WIDTH / 2 - 120,
      y: SCREEN_HEIGHT / 2 - 80,
      width: 240,
      height: 160
    }
    
    // 回调函数
    this.undoCallback = null
    this.surrenderCallback = null
    this.backToMenuCallback = null

    
    // 鼠标悬停状态
    this.hoveredButton = null
  }

  render(ctx) {
    if (!this.isVisible) return
    
    // 绘制控制面板背景
    this.drawPanelBackground(ctx)
    
    // 绘制按钮
    this.drawButtons(ctx)
    
    // 绘制菜单展开动画
    if (this.isMenuExpanded || this.menuAnimation > 0) {
      this.drawExpandedMenu(ctx)
    }
    
    // 绘制悔棋确认对话框
    if (this.undoConfirmDialog.isVisible) {
      this.drawUndoConfirmDialog(ctx)
    }
    
    // 绘制返回确认对话框
    if (this.backConfirmDialog.isVisible) {
      this.drawBackConfirmDialog(ctx)
    }
    
    // 绘制结束游戏确认对话框
    if (this.surrenderConfirmDialog.isVisible) {
      this.drawSurrenderConfirmDialog(ctx)
    }
  }

  drawPanelBackground(ctx) {
    // 绘制半透明背景
    ctx.fillStyle = 'rgba(0, 0, 0, 0)'
    ctx.fillRect(0, this.panelY, SCREEN_WIDTH, this.panelHeight)
    
    // 绘制顶部边框
    ctx.strokeStyle = 'rgba(255, 255, 255, 0)'
    ctx.lineWidth = 1
    ctx.beginPath()
    ctx.moveTo(0, this.panelY)
    ctx.lineTo(SCREEN_WIDTH, this.panelY)
    ctx.stroke()
  }

  drawButtons(ctx) {
    // 检查当前玩家是否还有悔棋次数
    const currentPlayer = this.databus.currentPlayer
    const canUndo = this.databus.canUndo(currentPlayer)
    
    // AI模式下的悔棋条件检查
    let shouldDisableUndo = !canUndo
    if (this.databus.isAIMode) {
      if (currentPlayer === this.databus.aiPlayer) {
        // AI不能悔棋
        shouldDisableUndo = true
      } else {
        // 玩家悔棋需要检查是否有足够的落子历史（至少2步）
        if (this.databus.moveHistory.length < 2) {
          shouldDisableUndo = true
        }
      }
    }
    
    // 绘制悔棋按钮（如果没有次数或AI模式下AI不能悔棋则显示为禁用状态）
    this.drawButton(ctx, this.undoButton, this.hoveredButton === 'undo', shouldDisableUndo)
    
    // 绘制菜单按钮
    this.drawButton(ctx, this.menuButton, this.hoveredButton === 'menu')
    
    // 绘制结束游戏按钮
    this.drawButton(ctx, this.surrenderButton, this.hoveredButton === 'surrender')
  }

  drawButton(ctx, button, isHovered, isDisabled = false) {
    let color = isHovered ? button.hoverColor : button.color
    
    // 如果按钮被禁用，使用灰色
    if (isDisabled) {
      color = '#9E9E9E'
    }
    
    // 绘制按钮背景
    ctx.fillStyle = color
    this.drawRoundedRect(ctx, button.x, button.y, button.width, button.height, 8)
    
    // 绘制按钮文字
    ctx.fillStyle = isDisabled ? '#666666' : '#ffffff'
    ctx.font = 'bold 16px Arial'
    ctx.textAlign = 'center'
    ctx.textBaseline = 'middle'
    ctx.fillText(button.text, button.x + button.width / 2, button.y + button.height / 2)
    
    // 绘制按钮边框
    ctx.strokeStyle = isDisabled ? '#666666' : (isHovered ? '#ffffff' : 'rgba(255, 255, 255, 0.3)')
    ctx.lineWidth = 2
    ctx.stroke()
  }

  drawRoundedRect(ctx, x, y, width, height, radius) {
    ctx.beginPath()
    ctx.moveTo(x + radius, y)
    ctx.lineTo(x + width - radius, y)
    ctx.quadraticCurveTo(x + width, y, x + width, y + radius)
    ctx.lineTo(x + width, y + height - radius)
    ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height)
    ctx.lineTo(x + radius, y + height)
    ctx.quadraticCurveTo(x, y + height, x, y + height - radius)
    ctx.lineTo(x, y + radius)
    ctx.quadraticCurveTo(x, y, x + radius, y)
    ctx.closePath()
    ctx.fill()
  }

  drawExpandedMenu(ctx) {
    // 绘制返回按钮（带动画）
    const animatedY = this.backButton.y + (1 - this.menuAnimation) * 20
    
    const backButton = {
      ...this.backButton,
      y: animatedY
    }
    
    this.drawButton(ctx, backButton, this.hoveredButton === 'back')
  }

  drawUndoConfirmDialog(ctx) {
    // 绘制半透明背景
    ctx.fillStyle = 'rgba(0, 0, 0, 0)'
    ctx.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)
    
    // 绘制对话框背景
    ctx.fillStyle = '#ffffff'
    this.drawRoundedRect(ctx, 
      this.undoConfirmDialog.x, 
      this.undoConfirmDialog.y, 
      this.undoConfirmDialog.width, 
      this.undoConfirmDialog.height, 
      12
    )
    
    // 绘制对话框边框
    ctx.strokeStyle = '#E91E63'
    ctx.lineWidth = 3
    ctx.stroke()
    
    // 绘制标题
    ctx.fillStyle = '#E91E63'
    ctx.font = 'bold 20px Arial'
    ctx.textAlign = 'center'
    ctx.fillText('确认悔棋', 
      this.undoConfirmDialog.x + this.undoConfirmDialog.width / 2,
      this.undoConfirmDialog.y + 30
    )
    
    // 获取当前玩家的悔棋次数
    const currentPlayer = this.databus.currentPlayer
    const remainingUndos = this.databus.getUndoCount(currentPlayer)
    const playerName = currentPlayer === 1 ? '红方' : '黑方'
    
    // 绘制提示文字
    ctx.fillStyle = '#666666'
    ctx.font = '16px Arial'
    ctx.fillText(`确定要悔棋吗？`, 
      this.undoConfirmDialog.x + this.undoConfirmDialog.width / 2,
      this.undoConfirmDialog.y + 50
    )
    
    // 绘制剩余次数信息
    ctx.fillStyle = '#E91E63'
    ctx.font = '14px Arial'
    ctx.fillText(`${playerName}剩余悔棋次数: ${remainingUndos}`, 
      this.undoConfirmDialog.x + this.undoConfirmDialog.width / 2,
      this.undoConfirmDialog.y + 75
    )
    
    // 绘制确认按钮
    const confirmButton = {
      x: this.undoConfirmDialog.x + 30,
      y: this.undoConfirmDialog.y + 100,
      width: 80,
      height: 35,
      text: '确定',
      color: '#E91E63',
      hoverColor: '#C2185B'
    }
    
    const cancelButton = {
      x: this.undoConfirmDialog.x + 130,
      y: this.undoConfirmDialog.y + 100,
      width: 80,
      height: 35,
      text: '取消',
      color: '#9E9E9E',
      hoverColor: '#757575'
    }
    
    this.drawButton(ctx, confirmButton, this.hoveredButton === 'confirm')
    this.drawButton(ctx, cancelButton, this.hoveredButton === 'cancel')
  }

  drawBackConfirmDialog(ctx) {
    // 绘制半透明背景
    ctx.fillStyle = 'rgba(0, 0, 0, 0)'
    ctx.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)
    
    // 绘制对话框背景
    ctx.fillStyle = '#ffffff'
    this.drawRoundedRect(ctx, 
      this.backConfirmDialog.x, 
      this.backConfirmDialog.y, 
      this.backConfirmDialog.width, 
      this.backConfirmDialog.height, 
      12
    )
    
    // 绘制对话框边框
    ctx.strokeStyle = '#F44336'
    ctx.lineWidth = 3
    ctx.stroke()
    
    // 绘制标题
    ctx.fillStyle = '#F44336'
    ctx.font = 'bold 20px Arial'
    ctx.textAlign = 'center'
    ctx.fillText('确认返回', 
      this.backConfirmDialog.x + this.backConfirmDialog.width / 2,
      this.backConfirmDialog.y + 30
    )
    
    // 绘制提示文字
    ctx.fillStyle = '#666666'
    ctx.font = '16px Arial'
    ctx.fillText('确定要返回主菜单吗？', 
      this.backConfirmDialog.x + this.backConfirmDialog.width / 2,
      this.backConfirmDialog.y + 60
    )
    
    // 绘制确认按钮
    const confirmButton = {
      x: this.backConfirmDialog.x + 30,
      y: this.backConfirmDialog.y + 100,
      width: 80,
      height: 35,
      text: '确定',
      color: '#F44336',
      hoverColor: '#D32F2F'
    }
    
    const cancelButton = {
      x: this.backConfirmDialog.x + 130,
      y: this.backConfirmDialog.y + 100,
      width: 80,
      height: 35,
      text: '取消',
      color: '#9E9E9E',
      hoverColor: '#757575'
    }
    
    this.drawButton(ctx, confirmButton, this.hoveredButton === 'backConfirm')
    this.drawButton(ctx, cancelButton, this.hoveredButton === 'backCancel')
  }

  drawSurrenderConfirmDialog(ctx) {
    // 绘制半透明背景
    ctx.fillStyle = 'rgba(0, 0, 0, 0)'
    ctx.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)
    
    // 绘制对话框背景
    ctx.fillStyle = '#ffffff'
    this.drawRoundedRect(ctx, 
      this.surrenderConfirmDialog.x, 
      this.surrenderConfirmDialog.y, 
      this.surrenderConfirmDialog.width, 
      this.surrenderConfirmDialog.height, 
      12
    )
    
    // 绘制对话框边框
    ctx.strokeStyle = '#FF5722'
    ctx.lineWidth = 3
    ctx.stroke()
    
    // 绘制标题
    ctx.fillStyle = '#FF5722'
    ctx.font = 'bold 20px Arial'
    ctx.textAlign = 'center'
    ctx.fillText('确认结束游戏', 
      this.surrenderConfirmDialog.x + this.surrenderConfirmDialog.width / 2,
      this.surrenderConfirmDialog.y + 30
    )
    
    // 获取当前玩家信息
    const currentPlayer = this.databus.currentPlayer
    const playerName = currentPlayer === 1 ? '红方' : '黑方'
    
    // 绘制提示文字
    ctx.fillStyle = '#666666'
    ctx.font = '16px Arial'
    ctx.fillText(`确定要结束本局游戏吗？`, 
      this.surrenderConfirmDialog.x + this.surrenderConfirmDialog.width / 2,
      this.surrenderConfirmDialog.y + 50
    )
    
    ctx.fillText(`${playerName}将结束游戏`, 
      this.surrenderConfirmDialog.x + this.surrenderConfirmDialog.width / 2,
      this.surrenderConfirmDialog.y + 75
    )
    
    // 绘制确认按钮
    const confirmButton = {
      x: this.surrenderConfirmDialog.x + 30,
      y: this.surrenderConfirmDialog.y + 100,
      width: 80,
      height: 35,
      text: '确定',
      color: '#FF5722',
      hoverColor: '#E64A19'
    }
    
    const cancelButton = {
      x: this.surrenderConfirmDialog.x + 130,
      y: this.surrenderConfirmDialog.y + 100,
      width: 80,
      height: 35,
      text: '取消',
      color: '#9E9E9E',
      hoverColor: '#757575'
    }
    
    this.drawButton(ctx, confirmButton, this.hoveredButton === 'surrenderConfirm')
    this.drawButton(ctx, cancelButton, this.hoveredButton === 'surrenderCancel')
  }

  handleTouch(x, y) {
    if (!this.isVisible) return false
    
    // 检查悔棋确认对话框
    if (this.undoConfirmDialog.isVisible) {
      return this.handleUndoConfirmTouch(x, y)
    }
    
    // 检查返回确认对话框
    if (this.backConfirmDialog.isVisible) {
      return this.handleBackConfirmTouch(x, y)
    }
    
    // 检查结束游戏确认对话框
    if (this.surrenderConfirmDialog.isVisible) {
      return this.handleSurrenderConfirmTouch(x, y)
    }
    
    // 检查菜单展开状态
    if (this.isMenuExpanded) {
      if (this.isPointInButton(x, y, this.backButton)) {
        this.hoveredButton = 'back'
        return true
      }
    }
    
    // 检查主按钮
    if (this.isPointInButton(x, y, this.undoButton)) {
      // 检查当前玩家是否还有悔棋次数
      const currentPlayer = this.databus.currentPlayer
      const canUndo = this.databus.canUndo(currentPlayer)
      
      // AI模式下的悔棋条件检查
      let canPerformUndo = canUndo
      if (this.databus.isAIMode) {
        if (currentPlayer === this.databus.aiPlayer) {
          // AI不能悔棋
          canPerformUndo = false
        } else {
          // 玩家悔棋需要检查是否有足够的落子历史（至少2步）
          if (this.databus.moveHistory.length < 2) {
            canPerformUndo = false
          }
        }
      }
      
      if (canPerformUndo) {
        this.hoveredButton = 'undo'
        return true
      }
    }
    
    if (this.isPointInButton(x, y, this.menuButton)) {
      this.hoveredButton = 'menu'
      return true
    }
    
    if (this.isPointInButton(x, y, this.surrenderButton)) {
      this.hoveredButton = 'surrender'
      return true
    }
    
    this.hoveredButton = null
    return false
  }

  handleUndoConfirmTouch(x, y) {
    const confirmButton = {
      x: this.undoConfirmDialog.x + 30,
      y: this.undoConfirmDialog.y + 100,
      width: 80,
      height: 35
    }
    
    const cancelButton = {
      x: this.undoConfirmDialog.x + 130,
      y: this.undoConfirmDialog.y + 100,
      width: 80,
      height: 35
    }
    
    if (this.isPointInButton(x, y, confirmButton)) {
      this.hoveredButton = 'confirm'
      return true
    }
    
    if (this.isPointInButton(x, y, cancelButton)) {
      this.hoveredButton = 'cancel'
      return true
    }
    
    this.hoveredButton = null
    return true
  }

  handleBackConfirmTouch(x, y) {
    const confirmButton = {
      x: this.backConfirmDialog.x + 30,
      y: this.backConfirmDialog.y + 100,
      width: 80,
      height: 35
    }
    
    const cancelButton = {
      x: this.backConfirmDialog.x + 130,
      y: this.backConfirmDialog.y + 100,
      width: 80,
      height: 35
    }
    
    if (this.isPointInButton(x, y, confirmButton)) {
      this.hoveredButton = 'backConfirm'
      return true
    }
    
    if (this.isPointInButton(x, y, cancelButton)) {
      this.hoveredButton = 'backCancel'
      return true
    }
    
    this.hoveredButton = null
    return true
  }

  handleSurrenderConfirmTouch(x, y) {
    const confirmButton = {
      x: this.surrenderConfirmDialog.x + 30,
      y: this.surrenderConfirmDialog.y + 100,
      width: 80,
      height: 35
    }
    
    const cancelButton = {
      x: this.surrenderConfirmDialog.x + 130,
      y: this.surrenderConfirmDialog.y + 100,
      width: 80,
      height: 35
    }
    
    if (this.isPointInButton(x, y, confirmButton)) {
      this.hoveredButton = 'surrenderConfirm'
      return true
    }
    
    if (this.isPointInButton(x, y, cancelButton)) {
      this.hoveredButton = 'surrenderCancel'
      return true
    }
    
    this.hoveredButton = null
    return true
  }

  isPointInButton(x, y, button) {
    return x >= button.x && x <= button.x + button.width &&
           y >= button.y && y <= button.y + button.height
  }

  handleClick(x, y) {
    if (!this.isVisible) return false
    
    // 检查悔棋确认对话框
    if (this.undoConfirmDialog.isVisible) {
      return this.handleUndoConfirmClick(x, y)
    }
    
    // 检查返回确认对话框
    if (this.backConfirmDialog.isVisible) {
      return this.handleBackConfirmClick(x, y)
    }
    
    // 检查认输确认对话框
    if (this.surrenderConfirmDialog.isVisible) {
      return this.handleSurrenderConfirmClick(x, y)
    }
    
    // 检查菜单展开状态
    if (this.isMenuExpanded) {
      if (this.isPointInButton(x, y, this.backButton)) {
        this.showBackConfirmDialog()
        return true
      }
    }
    
    // 检查主按钮
    if (this.isPointInButton(x, y, this.undoButton)) {
      // 隐藏菜单（返回按钮）
      this.hideMenu()
      
      // 检查当前玩家是否还有悔棋次数
      const currentPlayer = this.databus.currentPlayer
      const canUndo = this.databus.canUndo(currentPlayer)
      
      // AI模式下的悔棋条件检查
      let canPerformUndo = canUndo
      if (this.databus.isAIMode) {
        if (currentPlayer === this.databus.aiPlayer) {
          // AI不能悔棋
          canPerformUndo = false
        } else {
          // 玩家悔棋需要检查是否有足够的落子历史（至少2步）
          if (this.databus.moveHistory.length < 2) {
            canPerformUndo = false
          }
        }
      }
      
      if (canPerformUndo) {
        this.showUndoConfirmDialog()
        return true
      }
    }
    
    if (this.isPointInButton(x, y, this.menuButton)) {
      this.toggleMenu()
      return true
    }
    
    if (this.isPointInButton(x, y, this.surrenderButton)) {
      // 隐藏菜单（返回按钮）
      this.hideMenu()
      this.showSurrenderConfirmDialog()
      return true
    }
    
    return false
  }

  handleUndoConfirmClick(x, y) {
    const confirmButton = {
      x: this.undoConfirmDialog.x + 30,
      y: this.undoConfirmDialog.y + 100,
      width: 80,
      height: 35
    }
    
    const cancelButton = {
      x: this.undoConfirmDialog.x + 130,
      y: this.undoConfirmDialog.y + 100,
      width: 80,
      height: 35
    }
    
    if (this.isPointInButton(x, y, confirmButton)) {
      // 再次检查悔棋次数（防止在对话框显示期间次数被用完）
      const currentPlayer = this.databus.currentPlayer
      if (this.databus.canUndo(currentPlayer)) {
        this.hideUndoConfirmDialog()
        if (this.undoCallback) {
          this.undoCallback()
        }
      } else {
        // 如果没有次数了，只隐藏对话框
        this.hideUndoConfirmDialog()
      }
      return true
    }
    
    if (this.isPointInButton(x, y, cancelButton)) {
      this.hideUndoConfirmDialog()
      return true
    }
    
    return true
  }

  handleBackConfirmClick(x, y) {
    const confirmButton = {
      x: this.backConfirmDialog.x + 30,
      y: this.backConfirmDialog.y + 100,
      width: 80,
      height: 35
    }
    
    const cancelButton = {
      x: this.backConfirmDialog.x + 130,
      y: this.backConfirmDialog.y + 100,
      width: 80,
      height: 35
    }
    
    if (this.isPointInButton(x, y, confirmButton)) {
      this.hideBackConfirmDialog()
      this.hideMenu()
      if (this.backToMenuCallback) {
        this.backToMenuCallback()
      }
      return true
    }
    
    if (this.isPointInButton(x, y, cancelButton)) {
      this.hideBackConfirmDialog()
      return true
    }
    
    return true
  }

  handleSurrenderConfirmClick(x, y) {
    const confirmButton = {
      x: this.surrenderConfirmDialog.x + 30,
      y: this.surrenderConfirmDialog.y + 100,
      width: 80,
      height: 35
    }
    
    const cancelButton = {
      x: this.surrenderConfirmDialog.x + 130,
      y: this.surrenderConfirmDialog.y + 100,
      width: 80,
      height: 35
    }
    
    if (this.isPointInButton(x, y, confirmButton)) {
      this.hideSurrenderConfirmDialog()
      if (this.surrenderCallback) {
        this.surrenderCallback()
      }
      return true
    }
    
    if (this.isPointInButton(x, y, cancelButton)) {
      this.hideSurrenderConfirmDialog()
      return true
    }
    
    return true
  }

  toggleMenu() {
    this.isMenuExpanded = !this.isMenuExpanded
    if (this.isMenuExpanded) {
      this.animateMenuExpand()
    } else {
      this.animateMenuCollapse()
    }
  }

  showMenu() {
    this.isMenuExpanded = true
    this.animateMenuExpand()
  }

  hideMenu() {
    this.isMenuExpanded = false
    this.animateMenuCollapse()
  }

  animateMenuExpand() {
    const animate = () => {
      this.menuAnimation += 0.1
      if (this.menuAnimation < 1) {
        requestAnimationFrame(animate)
      } else {
        this.menuAnimation = 1
      }
    }
    animate()
  }

  animateMenuCollapse() {
    const animate = () => {
      this.menuAnimation -= 0.1
      if (this.menuAnimation > 0) {
        requestAnimationFrame(animate)
      } else {
        this.menuAnimation = 0
      }
    }
    animate()
  }

  showUndoConfirmDialog() {
    // AI模式下的悔棋条件检查
    const currentPlayer = this.databus.currentPlayer
    const canUndo = this.databus.canUndo(currentPlayer)
    
    if (this.databus.isAIMode) {
      if (currentPlayer === this.databus.aiPlayer) {
        // AI不能悔棋
        console.log('AI模式下，AI不能悔棋')
        return
      } else {
        // 玩家悔棋需要检查是否有足够的落子历史（至少2步）
        if (this.databus.moveHistory.length < 2) {
          console.log('AI模式悔棋：历史记录不足，无法悔棋')
          return
        }
      }
    }
    
    if (!canUndo) {
      console.log('没有悔棋次数了')
      return
    }
    
    this.undoConfirmDialog.isVisible = true
  }

  hideUndoConfirmDialog() {
    this.undoConfirmDialog.isVisible = false
    this.hoveredButton = null
  }

  showBackConfirmDialog() {
    this.backConfirmDialog.isVisible = true
  }

  hideBackConfirmDialog() {
    this.backConfirmDialog.isVisible = false
    this.hoveredButton = null
  }

  showSurrenderConfirmDialog() {
    this.surrenderConfirmDialog.isVisible = true
  }

  hideSurrenderConfirmDialog() {
    this.surrenderConfirmDialog.isVisible = false
    this.hoveredButton = null
  }

  setUndoCallback(callback) {
    this.undoCallback = callback
  }

  setBackToMenuCallback(callback) {
    this.backToMenuCallback = callback
  }

  setSurrenderCallback(callback) {
    this.surrenderCallback = callback
  }

  show() {
    this.isVisible = true
  }

  hide() {
    this.isVisible = false
    this.hideUndoConfirmDialog()
    this.hideBackConfirmDialog()
    this.hideSurrenderConfirmDialog()
    this.hideMenu()
  }

  update() {
    // 更新动画等
  }
} 